package com.design.cjm.behavioral.observer.example;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 老板具体观察者实现类
 *
 * @Author: Jie Ming Chen
 * @Date: 2018/9/24
 * @Version 1.0
 */
public class Boss implements Subject{

    private List<Observer> observers =  new ArrayList<>();

    private String action;

    @Override
    public void attach(Observer observer) {

        observers.add(observer);
    }

    @Override
    public void detach(Observer observer) {

        Iterator<Observer> it = observers.iterator();
        while (it.hasNext()) {
            if (it.next().equals(observer)) {
                it.remove();
            }
        }

    }

    @Override
    public void notifyOb() {

        for (Observer object: observers) {
            object.update();
        }
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }
}
